<?php
namespace Dashboard\Controller;
class DelController extends BaseController{
    public function del(){
        $id         = I('id');
        $type       = I('type');
        if($type == 1){
            $test    = sel("admin","",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了管理员：".$test['name'];
            $result  = del("admin",$id);
        }
        if($type == 2){  //视频课程删除
            //删除课程下的所有分类
            $goods = sels("goods","vedios","goods_zhu_id = {$id}");
            if($goods){
                foreach ($goods as $k=>$v){
                    unlink($v['vedios']);
                }
                $goods = del("goods",array("goods_zhu_id"=>$id));
            }
            $test  = sel("goods_zhu","img,title",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了课程：".$test['title'];
            $result  = del("goods_zhu",$id);
        }
        if($type == 3){  //视频分类课程删除
            $test  = sel("goods","vedios,title",array("id"=>$id));
            unlink($test['vedios']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了课程：".$test['title'];
            $result  = del("goods",$id);
        }

        if($type == 4){  //音频课程删除
            //删除课程下的所有分类
            $goods = sels("voices","voice","voice_zhu_id = {$id}");
            if($goods){
                foreach ($goods as $k=>$v){
                    unlink($v['voice']);
                }
                $goods = del("voices",array("voice_zhu_id"=>$id));
            }
            $test  = sel("voices_zhu","img,title",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了课程：".$test['title'];
            $result  = del("voices_zhu",$id);
        }
        if($type == 5){  //音频分类课程删除
            $test  = sel("voices","voice","id = {$id}");
            unlink($test['voice']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了课程：".$id;
            $result  = del("voices",$id);
        }

        if($type == 9){
            $test    = sel("goods"," * ",array("id"=>$id));
            unlink($test['banner']);
            $a_imgs = explode(",",$test['img']);
            $a_count = count($a_imgs);
            for($i=0;$i<$a_count;$i++){
                unlink($a_imgs[$i]);
            }
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了商品：{$test['name']}。";
            $result  = del("goods",$id);
        }
        if($type == 10){
            $test    = sel("orders","trade_no",array("id"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了订单编号为：{$test['trade_no']}的订单。";
            $result  = up_one("orders",array("id"=>$id),array("del"=>2));
        }
        if($type == 13){
            $test    = sel("icons","name,img",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了图标，用户名为：{$test['name']}的信息";
            $result  = del("icons",$id);
        }
        if($type == 14){
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了协议信息";
            $result  = del("xie",$id);
        }
        if($type == 15){
            //1资讯  2小程序订单轮播   3小程序首页轮播   4下单须知
            $test    = sel("news","img,title",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了一条资讯信息（{$test['title']}）";
            $result  = del("news",$id);
        }
        if($type == 17){
            $test    = sel("join_type","",array("id"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了加盟合作分类：{$test['name']}。";
            $result  = del("join_type",$id);
        }
        if($type == 18){ //删除最后一级
            $test    = sel("mei_type","",array("id"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了美容管理分类：{$test['name']}。";
            $result  = del("mei_type",$id);
        }
        if($type == 25){ //删除第二级
            //删除三级
            $san     = del("mei_type",array("pid"=>$id));
            $test    = sel("mei_type","",array("id"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了美容管理二级分类下的所有分类：{$test['name']}。";
            $result  = del("mei_type",array("id"=>$id));
        }
        if($type == 26){//删除顶级
            //删除三级
            $ss = sels("mei_type","id","pid = {$id}");
            if($ss){
                foreach ($ss as $k=>$v){$sss[] = $v['id'];}
                $er_id = implode(",",$sss);
                $san     = del("mei_type",array("pid"=>array("in",$er_id)));
                //删除二级
                $er      = del("mei_type",array("pid"=>$id));
            }
            $test    = sel("mei_type","",array("id"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了美容管理顶级分类：{$test['name']}。";
            $result  = del("mei_type",$id);
        }

        if($type == 20){
            $test    = sel("coupons","img,name",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了一条优惠券信息({$test['name']})";
            $result  = del("coupons",$id);
        }
        if($type == 21){
            $test     = sel("vip_type","",array("id"=>$id));
            $vip_type = del("vips",array("vip_type"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了vip分类：{$test['name']}。";
            $result  = del("vip_type",$id);
        }
        //加盟合作--资讯删除
        if($type == 22){
            $test    = sel("news","",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了资讯信息：{$test['title']}。";
            $result  = del("news",$id);
        }
        //美容管理资讯信息--删除
        if($type == 23){
            $test    = sel("news","img",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了资讯信息：{$test['title']}。";
            $result  = del("news",$id);
        }
        if($type == 24){
            $test    = sel("news_lun","",array("id"=>$id));
            unlink($test['img']);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了轮播图。{$test['lun_id']}";
            $result  = del("news_lun",$id);
        }
        //删除用户
        if($type == 25){
            $user    = sel("users","id,nickname",array("id"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了用户{$user['nickname']}";
            $result  = del("users",$id);
        }
        //删除核销历史记录
        if($type == 26){
            $user    = sel("covers_hostory","",array("id"=>$id));
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())." 删除了用户积分记录";
            $result  = del("covers_hostory",$id);
        }
        if($result){
            $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
            $this->ajaxReturn(array("status"=>1));
        }else{
            $this->ajaxReturn(array("status"=>2));
        }
    }
    public function alldel(){
        $type = $_POST['type'];
        $a    = $_POST['newsid'];
        $b    = implode(",", $a);
        if($type == 1){
            $logo = sels("school",array("id"=>array("in",$b)));
            foreach($logo as $k=>$v){
                unlink($v['img']);
                $imgs = explode(",",$v['imgs']);
                $count = count($imgs);
                for($i=0;$i<$count;$i++){unlink($imgs[$i]);}
            }
            $temp = dels("school",$b);
            if($temp){
                $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."批量删除了id为：‘".$b."’的商品";
                $log     = ins("logs",array("content"=>$content));
                $this->success("批量删除成功",U('Admin/School/index'));
            }
        }
    }
}